import time
from selenium.webdriver.common.by import By


def get_page_title(driver):
    return driver.title


def fhsj(driver):
    return driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text


def qd(driver):
    return driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[3]/div/div/div[1]').text


def save_screenshot(driver, filename):
    driver.save_screenshot(filename)


def login(driver, username, password):
    driver.get('http://localhost:90')
    driver.maximize_window()
    driver.find_element(By.ID, "username").send_keys(username)
    driver.find_element(By.ID, "password").send_keys(password)
    time.sleep(2)
    driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
    time.sleep(1)


def zc(driver, username, password, repassword):
    driver.get('http://localhost:90')
    driver.maximize_window()
    driver.find_element(By.XPATH, '/html/body/div/div/div/div[2]/a').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="username"]').send_keys(username)
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(password)
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="repassword"]').send_keys(repassword)
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
    time.sleep(1)


def xzyhk(driver, bkname, yhkh):
    driver.get('http://localhost:90')
    driver.maximize_window()
    driver.find_element(By.ID, "username").send_keys('lisi')
    driver.find_element(By.ID, "password").send_keys('123456')
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="bankCard_add_modal_btn"]').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="cardBank_add_input"]').send_keys(bkname)
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="cardNum_add_input"]').send_keys(yhkh)
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="bankCard_save_btn"]').click()


def scyhk(driver, username, password):
    driver.get('http://localhost:90')
    driver.maximize_window()
    driver.find_element(By.ID, "username").send_keys(username)
    driver.find_element(By.ID, "password").send_keys(password)
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[3]/div/div/div[1]/ul/li/button[2]').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
    qd = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[3]/div/div/div[1]').text
    return qd


def wangdai(driver, money, day):
    driver.get('http://localhost:90')
    driver.maximize_window()
    driver.find_element(By.ID, "username").send_keys('lisi')
    driver.find_element(By.ID, "password").send_keys('123456')
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="amount"]').send_keys(money)
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="term"]').send_keys(day)
    time.sleep(1)
    driver.find_element(By.XPATH, '//*[@id="submit"]').click()
    time.sleep(1)
    driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
    time.sleep(1)

